package com.jic.manager.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.manager.mapper.PublicnumTypeMapper;
import com.jic.manager.entity.PublicnumType;
import com.jic.conf.request.PublicNumTypeRequest;
import com.jic.conf.response.PublicNumTypeResponse;
import com.jic.manager.service.PublicnumTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 公众号类型
 * @author : 
 * @email : 
 * @since : 2020-02-16 01:49:12
 * @version : v1.0.0
 */
@Service
public class PublicnumTypeServiceImpl implements PublicnumTypeService {

    @Autowired
    private PublicnumTypeMapper publicnumTypeMapper;

    @Override
    public long insert(PublicNumTypeRequest publicNumTypeRequest) {
        long flag = publicnumTypeMapper.insert(publicNumTypeRequest);
        return flag;
    }

    @Override
    public long delete(PublicnumType id) {
        return publicnumTypeMapper.delete(id);
    }

    @Override
    public long update(PublicNumTypeRequest publicNumTypeRequest) {
        return publicnumTypeMapper.update(publicNumTypeRequest);
    }

    @Override
    public PublicnumType queryByPrimaryKey(Long id){
        return publicnumTypeMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<PublicnumType> query(PublicnumType publicnumType){
        return publicnumTypeMapper.query(publicnumType);
    }

    @Override
    public PageResult<PublicNumTypeResponse> queryPage(PublicnumType publicnumType, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<PublicNumTypeResponse> list = publicnumTypeMapper.queryPage(startIndex, pageQuery.getLimit(), publicnumType);
        long count = publicnumTypeMapper.queryPageCount(publicnumType);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}